class AdminController < ActionController::Base
  before_filter :require_login
  before_filter :require_admin
  protect_from_forgery

  before_filter :set_user_language

  def require_login
    if !session[:user]
      redirect_to session_login_path
    end
  end
  
  def require_admin
    if !session[:user]
      redirect_to session_login_path
    else 
       user = session[:user]
       if user.role != ADMIN_ROLE
          redirect_to session_ban_path
       end
    end
  end
  
  private
  def set_user_language
    if session[:language]
      language = session[:language]
      if language == 'vi'
        I18n.locale = 'vi'
      elsif language == 'en'
        I18n.locale = 'en'
      else
        I18n.locale = 'en'        
      end
    else
      I18n.locale = 'en'
    end
  end
end